home *** CD-ROM | disk | FTP | other *** search
- /*
- ***** BEGIN LICENSE BLOCK *****
- Version: MPL 1.1/GPL 2.0/LGPL 2.1
-
- The contents of this file are subject to the Mozilla Public License Version
- 1.1 (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
- http://www.mozilla.org/MPL/
-
- Software distributed under the License is distributed on an "AS IS" basis,
- WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- for the specific language governing rights and limitations under the
- License.
-
- The Original Code is RAYS RS.
-
- The Initial Developer of the Original Code is
- SAKURAI Kenichi <http://something.cool.coocan.jp/kenichi/>.
- Portions created by the Initial Developer are Copyright (C) 2010
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
-
- Alternatively, the contents of this file may be used under the terms of
- either the GNU General Public License Version 2 or later (the "GPL"), or
- the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- in which case the provisions of the GPL or the LGPL are applicable instead
- of those above. If you wish to allow use of your version of this file only
- under the terms of either the GPL or the LGPL, and not to allow others to
- use your version of this file under the terms of the MPL, indicate your
- decision by deleting the provisions above and replace them with the notice
- and other provisions required by the GPL or the LGPL. If you do not delete
- the provisions above, a recipient may use your version of this file under
- the terms of any one of the MPL, the GPL or the LGPL.
-
- ***** END LICENSE BLOCK *****
- */
-
- var raysRs = {};
-
- raysRs.httpRequestRa = null;
- raysRs.httpRequestAm = null;
- raysRs.httpRequestYs = null;
- raysRs.currentLocale;
-
- raysRs.isJapan = function(){
- return (/^ja/.test (raysRs.currentLocale));
- };
-
- raysRs.removeAllChild = function (element){
- for (;element.firstChild;){
- element.removeChild (element.firstChild);
- }
- };
-
- raysRs.needReload = function (element, interval){
- var itemTimestamp = element.getAttribute ("rays_rs_item_timestamp");
- var genreTimestamp = element.getAttribute ("rays_rs_genre_timestamp");
- var now;
-
- var result = true;
-
- if (itemTimestamp != null && itemTimestamp != "" && genreTimestamp != null && genreTimestamp != ""){
- now = new Date().getTime();
- if (interval * 1000 > now - parseInt (itemTimestamp) || interval * 1000 > now - parseInt (genreTimestamp)){
- result = false;
- }
- }
-
- return result;
- };
-
- raysRs.evaluateXPath = function (aNode, aExpr){
- var xpe = new XPathEvaluator();
- var nsResolver = xpe.createNSResolver (aNode.ownerDocument == null ? aNode.documentElement : aNode.ownerDocument.documentElement);
- var result = xpe.evaluate (aExpr, aNode, nsResolver, 0, null);
- var found = [];
- var res;
-
- while (res = result.iterateNext()){
- found.push (res);
- }
-
- return found;
- };
-
- raysRs.infoReceived = function(){
- };
-
- raysRs.recordRakutenImpression = function(){
- };
-
- raysRs.recordAmazonImpression = function(){
- httpRequestAm = new XMLHttpRequest();
- httpRequestAm.open ("GET", "http://www.assoc-amazon.jp/e/ir?o=9&t=kenichisspace-22&l=wsw&camp=759&creative=7995");
- httpRequestAm.onload = raysRs.infoReceived;
- try{
- httpRequestAm.send (null);
- } catch (e){
- }
- };
-
- raysRs.recordYahooShoppingImpression = function(){
- httpRequestYs = new XMLHttpRequest();
- httpRequestYs.open ("GET", "http://ad.jp.ap.valuecommerce.com/servlet/gifbanner?sid=2333728&pid=878835741");
- httpRequestYs.onload = raysRs.infoReceived;
- try{
- httpRequestYs.send (null);
- } catch (e){
- }
- };
-
- raysRs.recordAmazonUsImpression = function(){
- httpRequestAm = new XMLHttpRequest();
- httpRequestAm.open ("GET", "http://www.assoc-amazon.com/e/ir?o=1&t=kenichisspace-20&l=wsw&camp=212361&creative=392009");
- httpRequestAm.onload = raysRs.infoReceived;
- try{
- httpRequestAm.send (null);
- } catch (e){
- }
- };
-
- raysRs.recordImpression = function(){
- if (raysRs.isJapan()){
- raysRs.recordRakutenImpression();
- raysRs.recordAmazonImpression();
- raysRs.recordYahooShoppingImpression();
- } else{
- raysRs.recordAmazonUsImpression();
- }
- };
-
- raysRs.init = function(){
- var contentArea = document.getElementById ("contentAreaContextMenu");
- contentArea.addEventListener ("popupshowing", this, false);
-
- raysRs.currentLocale = Components.
- classes["@mozilla.org/preferences-service;1"].
- getService (Components.interfaces.nsIPrefService).
- getBranch ('').
- getCharPref ('general.useragent.locale');
-
- raysRs.recordImpression();
-
- if (raysRs.isJapan()){
- document.getElementById ("rays_rs_menu_am_us_ranking").hidden = true;
- } else{
- document.getElementById ("rays_rs_menu_ra_ranking").hidden = true;
- document.getElementById ("rays_rs_menu_am_ranking").hidden = true;
- document.getElementById ("rays_rs_menu_ys_ranking").hidden = true;
- }
- };
-
- raysRs.handleEvent = function (event){
- var menuseparator;
- var menuitemRa;
- var menuitemAm;
- var menuitemYs;
- var menuitemAl;
- var menuitemAmUs;
- var selected;
-
- if (event.type == "popupshowing" && event.target == event.currentTarget){
- selected = getBrowserSelection() != "";
- menuseparator = document.getElementById ("rays_rs_menuseparator");
- menuitemRa = document.getElementById ("rays_rs_menuitem_ra");
- menuitemAm = document.getElementById ("rays_rs_menuitem_am");
- menuitemYs = document.getElementById ("rays_rs_menuitem_ys");
- menuitemAl = document.getElementById ("rays_rs_menuitem_al");
- menuitemAmUs = document.getElementById ("rays_rs_menuitem_am_us");
- menuseparator.hidden = !selected;
- menuitemRa.hidden = !selected;
- menuitemAm.hidden = !selected;
- menuitemYs.hidden = !selected;
- menuitemAl.hidden = !selected;
- menuitemAmUs.hidden = !selected;
-
- if (raysRs.isJapan()){
- menuitemAmUs.hidden = true;
- } else{
- menuitemRa.hidden = true;
- menuitemAm.hidden = true;
- menuitemYs.hidden = true;
- menuitemAl.hidden = true;
- }
- }
- };
-
- raysRs.searchRakuten = function (arg){
- gBrowser.addTab ("http://pt.afl.rakuten.co.jp/c/0017caac.46f19b8a/?sv=2&p=0&sitem=" + getBrowserSelection());
- };
-
- raysRs.searchAmazon = function (arg){
- gBrowser.addTab ("http://www.amazon.co.jp/s/?tag=kenichisspace-22&creative=7995&campaign=759&link_code=wsw&__mk_ja_JP=\u30AB\u30BF\u30AB\u30CA&search-alias=aps&field-keywords=" + getBrowserSelection());
- };
-
- raysRs.searchYahooShopping = function (arg){
- gBrowser.addTab ("http://ck.jp.ap.valuecommerce.com/servlet/referral?sid=2333728&pid=878835741&vc_url=http%3a%2f%2fshopping%2eyahoo%2eco%2ejp%2fsearch%3ffirst%3d1%26cid%3d%26p%3d" + getBrowserSelection());
- };
-
- raysRs.searchAmazonUs = function (arg){
- gBrowser.addTab ("http://www.amazon.com/s/?tag=kenichisspace-20&creative=392009&campaign=212361&link_code=wsw&_encoding=UTF-8&search-alias=aps&field-keywords=" + getBrowserSelection());
- };
-
- raysRs.searchAll = function (arg){
- raysRs.searchRakuten (arg);
- raysRs.searchAmazon (arg);
- raysRs.searchYahooShopping (arg);
- };
-
- raysRs.fetchRakuten = function (element, separator, item, url, id, gender, generation){
- var httpRequest = null;
- var json;
-
- function infoReceived(){
- var data = httpRequest.responseText;
- var i;
- var ptr1;
- var ptr2;
-
- if (data.length){
- json = JSON.parse (data);
-
- if (item){
- if (json.Body && json.Body['ItemRanking']){
- for (i = 0; i < json.Body['ItemRanking'].Items.Item.length; i++){
- ptr1 = document.createElement ("menuitem");
- ptr1.setAttribute ("label", json.Body['ItemRanking'].Items.Item[i].itemName);
- ptr1.setAttribute ("oncommand", "gBrowser.addTab('" + json.Body['ItemRanking'].Items.Item[i].affiliateUrl + "');");
- element.appendChild (ptr1);
- }
- }
-
- element.setAttribute ("rays_rs_item_timestamp", "" + new Date().getTime());
- } else{
- for (i = 0; i < json.Body['GenreSearch'].child.length; i++){
- ptr1 = document.createElement ("menu");
- ptr1.setAttribute ("label", json.Body['GenreSearch'].child[i].genreName);
- element.insertBefore (ptr1, separator);
- ptr2 = document.createElement ("menupopup");
- ptr2.setAttribute ("id", id + "_" + json.Body['GenreSearch'].child[i].genreId);
- ptr2.setAttribute ("onpopupshowing",
- "raysRs.rankingRakuten('" +
- id +
- "_" +
- json.Body['GenreSearch'].child[i].genreId +
- "',null,null," +
- json.Body['GenreSearch'].child[i].genreId +
- ");");
- ptr1.appendChild (ptr2);
- }
-
- element.setAttribute ("rays_rs_genre_timestamp", "" + new Date().getTime());
- }
- }
- }
-
- httpRequest = new XMLHttpRequest();
-
- httpRequest.open ("GET", url);
-
- httpRequest.onload = infoReceived;
- try{
- httpRequest.send (null);
- } catch (e){
- }
- };
-
- raysRs.fetchAmazon = function (element, separator, item, url, country, root, index, id){
- var httpRequest = null;
-
- function infoReceived(){
- var data = httpRequest.responseText;
- var dom;
- var i;
- var items;
- var ptr1;
- var ptr2;
-
- if (data.length){
- data = data.replace (/ xmlns=\"http:\/\/webservices\.amazon\.com\/AWSECommerceService\/2006-09-13\"/, "");
- dom = new DOMParser().parseFromString (data, "text/xml");
-
- if (item){
- items = raysRs.evaluateXPath (dom.documentElement, "/ItemSearchResponse/Items/Item");
-
- for (i = 0; i < items.length; i++){
- ptr1 = document.createElement ("menuitem");
- ptr1.setAttribute ("label", items[i].lastChild.lastChild.firstChild.nodeValue);
- ptr1.setAttribute ("oncommand", "gBrowser.addTab('" + items[i].firstChild.nextSibling.firstChild.nodeValue + "');");
- element.appendChild (ptr1);
- }
-
- element.setAttribute ("rays_rs_item_timestamp", "" + new Date().getTime());
- } else{
- items = raysRs.evaluateXPath (dom.documentElement, "/BrowseNodeLookupResponse/BrowseNodes/BrowseNode/Children/BrowseNode");
-
- for (i = 0; i < items.length; i++){
- ptr1 = document.createElement ("menu");
- ptr1.setAttribute ("label", items[i].lastChild.firstChild.nodeValue);
- element.insertBefore (ptr1, separator);
- ptr2 = document.createElement ("menupopup");
- ptr2.setAttribute ("id", id + "_" + items[i].firstChild.firstChild.nodeValue);
- ptr2.setAttribute ("onpopupshowing",
- "raysRs.rankingAmazon('" +
- id +
- "_" +
- items[i].firstChild.firstChild.nodeValue +
- "','" +
- country +
- "','" +
- root +
- "'," +
- items[i].firstChild.firstChild.nodeValue +
- ");");
- ptr1.appendChild (ptr2);
- }
-
- element.setAttribute ("rays_rs_genre_timestamp", "" + new Date().getTime());
- }
- }
- }
-
- httpRequest = new XMLHttpRequest();
-
- httpRequest.open ("GET", url);
-
- httpRequest.onload = infoReceived;
- try{
- httpRequest.send (null);
- } catch (e){
- }
- };
-
- raysRs.fetchYahooShopping = function (element, separator, item, url, id, gender, generation, period){
- var httpRequest = null;
-
- function infoReceived(){
- var data = httpRequest.responseText;
- var i;
- var ptr1;
- var ptr2;
-
- if (data.length){
- json = JSON.parse (data);
-
- if (item){
- for (i in json.ResultSet["0"].Result){
- if (!isFinite (parseInt (i))){
- continue;
- }
- if (json.ResultSet["0"].Result[i].Name){
- ptr1 = document.createElement ("menuitem");
- ptr1.setAttribute ("label", json.ResultSet["0"].Result[i].Name);
- ptr1.setAttribute ("oncommand", "gBrowser.addTab('" + json.ResultSet["0"].Result[i].Url + "');");
- element.appendChild (ptr1);
- }
- }
-
- element.setAttribute ("rays_rs_item_timestamp", "" + new Date().getTime());
- } else{
- for (i in json.ResultSet["0"].Result.Categories.Children){
- if (!isFinite (parseInt(i))){
- continue;
- }
- ptr1 = document.createElement ("menu");
- ptr1.setAttribute ("label", json.ResultSet["0"].Result.Categories.Children[i].Title.Short);
- element.insertBefore (ptr1, separator);
- ptr2 = document.createElement ("menupopup");
- ptr2.setAttribute ("id", id + "_" + json.ResultSet["0"].Result.Categories.Children[i].Id);
- ptr2.setAttribute ("onpopupshowing",
- "raysRs.rankingYahooShopping('" +
- id +
- "_" +
- json.ResultSet["0"].Result.Categories.Children[i].Id +
- "',null,null,null," +
- json.ResultSet["0"].Result.Categories.Children[i].Id +
- ");");
- ptr1.appendChild (ptr2);
- }
-
- element.setAttribute ("rays_rs_genre_timestamp", "" + new Date().getTime());
- }
- }
- }
-
- httpRequest = new XMLHttpRequest();
-
- httpRequest.open ("GET", url);
-
- httpRequest.onload = infoReceived;
- try{
- httpRequest.send (null);
- } catch (e){
- }
- };
-
- raysRs.rankingRakuten = function (id, gender, generation, index){
- var element = document.getElementById (id);
- var url;
-
- if (raysRs.needReload (element, 3600 * 12)){
- raysRs.removeAllChild (element);
- element.appendChild (document.createElement ("menuseparator"));
-
- raysRs.fetchRakuten (element,
- element.lastChild,
- false,
- "http://api.rakuten.co.jp/rws/2.0/json?developerId=170e17ad1df9e7d3fc9cc7a1c8f5c0c9&affiliateId=0421aec8.d8170691.0421aec9.53c180f4&operation=GenreSearch&genreId=" +
- index +
- "&version=2007-04-11&genrePath=0",
- id,
- gender,
- generation);
-
- url = "http://api.rakuten.co.jp/rws/2.0/json?developerId=170e17ad1df9e7d3fc9cc7a1c8f5c0c9&affiliateId=0421aec8.d8170691.0421aec9.53c180f4&operation=ItemRanking&version=2009-04-15&genreId=" + index;
-
- raysRs.fetchRakuten (element, element.lastChild, true, url, id, gender, generation);
- }
- };
-
- raysRs.rankingAmazon = function (id, country, root, index){
- var element = document.getElementById (id);
-
- if (raysRs.needReload (element, 1800)){
- raysRs.removeAllChild (element);
- element.appendChild (document.createElement ("menuseparator"));
-
- raysRs.fetchAmazon (element,
- element.lastChild,
- false,
- "http://amazonadapi.appspot.com/" + country + "/?Operation=BrowseNodeLookup&BrowseNodeId=" + index,
- country,
- root,
- index,
- id);
-
- raysRs.fetchAmazon (element,
- element.lastChild,
- true,
- "http://amazonadapi.appspot.com/" + country + "/?Operation=ItemSearch&SearchIndex=" + root + "&BrowseNode=" + index,
- country,
- root,
- index,
- id);
- }
- };
-
- raysRs.rankingYahooShopping = function (id, gender, generation, period, index){
- var element = document.getElementById (id);
-
- if (raysRs.needReload (element, 3600 * 12)){
- raysRs.removeAllChild (element);
- element.appendChild (document.createElement ("menuseparator"));
-
- raysRs.fetchYahooShopping (element,
- element.lastChild,
- false,
- "http://shopping.yahooapis.jp/ShoppingWebService/V1/json/categorySearch?appid=qPMhN0Kxg64IvbyejiqKJ4mQog6c4Nmz1JPiGJE.qVyHteSj7lQhb8WrhULGUBT_Rg--&affiliate_type=vc&affiliate_id=http%3A%2F%2Fck.jp.ap.valuecommerce.com%2Fservlet%2Freferral%3Fsid%3D2333728%26pid%3D875961490%26vc_url%3D&category_id=" +
- index,
- id,
- gender,
- generation,
- period);
-
- raysRs.fetchYahooShopping (element,
- element.lastChild,
- true,
- "http://shopping.yahooapis.jp/ShoppingWebService/V1/json/categoryRanking?appid=qPMhN0Kxg64IvbyejiqKJ4mQog6c4Nmz1JPiGJE.qVyHteSj7lQhb8WrhULGUBT_Rg--&affiliate_type=vc&affiliate_id=http%3A%2F%2Fck.jp.ap.valuecommerce.com%2Fservlet%2Freferral%3Fsid%3D2333728%26pid%3D875961490%26vc_url%3D&category_id=" +
- index,
- id,
- gender,
- generation,
- period);
- }
- };
-
- window.addEventListener ("load", function(){raysRs.init();}, false);
-
- //next step: gender, age, period Yahoo&Rakuten
-